<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
    <title>存定期</title>
    <link rel="stylesheet" href="css/reset.css">
    <link rel="stylesheet" href="css/jiazai.css">
    <style>
        .hea-con {
            padding: 10px 20px 0;
            font-size: 16px;
            color: white;
            opacity: .7;
        }
        
        .input-wrap {
            padding: 20px;
            box-sizing: border-box;
        }
        
        .input-wrap>input {
            width: 100%;
            box-sizing: border-box;
            padding: 15px 10px;
            margin-top: 15px;
            font-size: 16px;
            color: white;
            background: #353742;
            border-radius: 5px;
        }
        
        .have-money {
            padding-top: 10px;
            font-size: 14px;
            color: #9197ae;
        }
        
        .input-wrap>p {
            margin-top: 50px;
            padding: 16px;
            text-align: center;
            font-size: 18px;
            color: rgba(255, 255, 255, .6);
            background: #353742;
            border-radius: 5px;
        }
        
        .invi-code {
            padding: 15px 10px;
            margin-top: 15px;
            font-size: 16px;
            color: rgba(255, 255, 255, .6);
            background: #353742;
            border-radius: 5px;
        }
        
        .invi-code>input {
            flex: 1 1 0;
            width: 100%;
            color: white;
            background: transparent;
        }
        
        .invi-code>span {
            flex: 0 0 80px;
            font-size: 13px;
            text-align: right;
            opacity: .7;
        }
        /* 状态提示框 */
        
        #mask-notice {
            position: fixed;
            top: 0;
            right: 0;
            bottom: 0;
            left: 0;
            z-index: 999;
            box-sizing: border-box;
            display: flex;
            justify-content: center;
            align-items: center;
            background: rgba(0, 0, 0, .5);
        }
        
        #mask-notice>.mask-content-wrap {
            width: 70%;
            background: white;
        }
        
        #mask-notice>.mask-content-wrap>h1 {
            padding: 45px 0;
            font-size: 15px;
            text-align: center;
        }
        
        #mask-notice>.mask-content-wrap>p {
            display: flex;
            justify-content: space-around;
            align-items: center;
            padding: 15px 0;
            font-size: 15px;
            text-align: center;
            color: #2590FE;
            background: #F5F5F5;
        }
        /* 状态提示框 */
    </style>
</head>

<body style="background:#2a2c35;">
    <div id='app'>


        <!-- 加载中动画 -->
        <div id='jiazai-ani' v-if='jiazai'>
            <div class="arc"></div>
            <h1><span>LOADING</span></h1>
        </div>
        <!-- 加载中动画 -->

        <!-- 状态提示框 -->
        <div id='mask-notice' v-if='offType'>
            <div class='mask-content-wrap'>
                <h1>存入定期完成</h1>
                <p>
                    <span style="color:#999;" @click='offType=false'>返回</span>
                    <span>查看记录</span>
                </p>
            </div>
        </div>
        <!-- 状态提示框 -->

        <div class='hea-con dis-spa'>
            <img @click='_close()' src="./img/left.svg" width="22px" height="22px">
            <span>
                存定期
            </span>
            <span style="opacity:0">1</span>
        </div>

        <div class='input-wrap'>
            <div class='have-money dis-spa'>
                <span>
                    可用余额
                </span>
                <p class='dis-spa'>
                    <span style="color:white;" v-text='cunData.money'>113.411</span>
                    <span>cc</span>
                </p>
            </div>
            <div class='invi-code dis-spa'>
                <input type="text" :placeholder="'最低投资'+parseInt(cunData.regular_min)+'枚'" v-model='count'>
                <span @click='count=cunData.money;'>全部存入</span>
            </div>
            <div class='have-money dis-spa'>
                <span>
                    返利{{cunData.powertext}}
                </span>
                <span style="color:white;" v-text='_toFixed(comMon,2)'>113.411</span>
            </div>
            <!-- 输入了后背景变为2590FE -->
            <p style="background:#2590FE;" @click='goCun'>立即存入</p>
        </div>
        <p style='padding-left:20px;color: #9197ae;'>可到定期账单查看本金+返利</p>
    </div>
    <script src="js/comm.js"></script>
    <script src="js/vue.min.js"></script>
    <script src="js/jquery.min.js"></script>
    <script>
        var app = new Vue({
            el: '#app',
            data: {
                jiazai: false,
                //状态提示框
                offType: false,
                //输入数据
                count: '',
                //本页数据
                cunData: {}
            },
            created: function() {
                this.getData();
            },
            computed: {
                comMon: function() {
                    if (this.count) {
                        return parseFloat(this.count) * parseFloat(this.cunData.power);
                    }
                    return 0;
                }
            },
            methods: {
                //得到本页数据
                getData: function(msg) {
                    var This = this;
                    This.jiazai = true;
                    var user = JSON.parse(localStorage.getItem('cc_user'));
                    _post(CUN_DINQI, {
                        userid: user.userid,
                        session: user.session
                    }, function(data) {
                        This.jiazai = false;
                        if (data.status == 1) {
                            if (msg) {
                                _toast(msg);
                                This.count = '';
                            }
                            This.cunData = data.back;
                        } else {
                            _toast(data.msg);
                        }
                    })
                },
                //立即存入
                goCun: function() {
                    if (!_ifNum(this.count, 'float')) {
                        _toast('请输入正确的CC额度');
                        this.count = '';
                        return;
                    }
                    var This = this;
                    var curr = plus.webview.currentWebview();
                    curr.setStyle({
                        mask: 'rgba(0,0,0,0.5)'
                    });
                    curr.addEventListener('maskClick', function() {
                        plus.webview.currentWebview().setStyle({
                            mask: 'none'
                        });
                        web.close('none');
                    }, false);

                    //打开输入密码页面
                    var op = {
                        'backButtonAutoControl': 'close', //返回是关闭当前页
                        'animationOptimization': 'none', //不优化
                        'background': 'transparent'
                    };
                    this.jiazai = true;
                    var web = plus.webview.create('input-password.html', 'inputPassword', op);
                    web.addEventListener("loaded", function() {
                        var user = JSON.parse(localStorage.getItem('cc_user'));
                        var send = {
                            amount: This.count
                        };
                        setTimeout(function() {
                            web.evalJS("send('" + CUN_DATA + "','" + JSON.stringify(send) + "')");
                            This.jiazai = false;
                            web.show('fade-in');
                        }, 200);
                    }, false);
                    web.onclose = function() {
                        var all = plus.webview.all();
                        for (var i = 0; i < all.length; i++) {
                            all[i].setStyle({
                                mask: 'none'
                            });
                        }
                    };





                    // var user = JSON.parse(localStorage.getItem('cc_user'));
                    // var This = this;
                    // This.jiazai = true;
                    // _post(CUN_DATA, {
                    //     userid: user.userid,
                    //     session: user.session,
                    //     amount: This.count
                    // }, function(data) {
                    //     if (data.status == 1) {
                    //         This.getData(data.msg);
                    //     } else {
                    //         This.jiazai = false;
                    //         _toast(data.msg);
                    //     }
                    // });
                }
            }
        });
    </script>
</body>

</html>